/**
 * @file /include/rhzd_assist/main_window.hpp
 *
 * @brief Qt based gui for rhzd_assist.
 *
 * @date October 2025
 **/
#ifndef _QT_ROS2_MAIN_WINDOW_HPP_
#define _QT_ROS2_MAIN_WINDOW_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include <QtWidgets/QMainWindow>
#include <QtGui>
#include <QTimer>
#include <QJsonObject>

#include "ui_main_window.h"
#include "qnode.hpp"
#include "dynamic_button.hpp"

/*****************************************************************************
** Namespace
*****************************************************************************/

namespace rhzd_assist {

/*****************************************************************************
** Interface [MainWindow]
*****************************************************************************/
/**
 * @brief Qt central, all operations relating to the view part here.
 */
class MainWindow : public QMainWindow {
Q_OBJECT

public:
    MainWindow(int argc, char** argv, QWidget *parent = 0);
    ~MainWindow();

protected:
    void closeEvent(QCloseEvent *event);
    void keyPressEvent(QKeyEvent *event) override;

Q_SIGNALS:
    void sigSend(QString strMsg);

public slots:
    /******************************************
    ** Auto-connections (connectSlotsByName())
    *******************************************/

private slots:
    void slot_battery_state(double);
    void on_mn_addcmd_triggered(void);
    void on_cb_open_image_clicked(bool checked);
    void on_rb_image_raw_toggled(bool toggled);
    void on_rb_image_depth_toggled(bool toggled);
    void updata_image(QImage);
    void on_dbutton_delete(DynamicButton *button);

private:
    Ui::MainWindow ui;
    QNode qnode;
    double battery_voltage;
    QString buttons_cfg_file_path;
    QList<DynamicButton*> button_list;
    QProcess *_cmd = NULL;

private:
    void load_dynamic_buttons(void);
    void save_dynamic_buttons(void);
    void add_dynamic_button(QString button_name, QString action);
    QJsonObject create_button_object(const QString &name, const QString &action);
};

}  // namespace rhzd_assist

#endif // _QT_ROS2_MAIN_WINDOW_HPP_
